<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">


		<div class="layui-input-inline">
			<div class="layui-inline">
				<input type="text" class="layui-input date" readonly id="start" placeholder="下单时间-起" style="width: 120px;">
			</div>
			<div class="layui-inline">
				<input type="text" class="layui-input date" readonly id="end" placeholder="下单时间-止" style="width: 120px;">
			</div>
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="order_sn" placeholder="订单号" style="width: 170px;">
		</div>
		<div class="layui-inline">
			<input type="text"  placeholder="乘客手机号"  class="layui-input" id="passenger_phone" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" placeholder="司机手机号"  class="layui-input" id="driver_phone" style="width: 130px;">
		</div>


		<div class="layui-inline">
			<select lay-verify="required" lay-search="" id="order_status" class="layui-input" style="width: 120px;">
				<option value="">订单状态</option>
				<volist name="orderStatusName" id="status">
					<option value="{$key}">{$status}</option>
				</volist>
			</select>
		</div>

		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
		</div>

	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Order/index')}', page: true, limit: 10, id:'test'}" lay-filter="test">
		<thead>
		<tr>
			<th lay-data="{field:'common_id', width:70,align:'center',fixed: true}">ID</th>
			<th lay-data="{field:'order_sn', width:190,align:'center'}">订单号</th>
			<th lay-data="{field:'passenger_phone', width:120,align:'center'}">乘客手机号</th>
			<th lay-data="{field:'order_time', width:120,align:'center'}">下单时间</th>
			<th lay-data="{field:'start_name', width:120,align:'center'}">出发地点</th>
			<th lay-data="{field:'arrive_name', width:120,align:'center'}">目的地</th>
			<th lay-data="{field:'on_car_time', width:120,align:'center'}">上车时间</th>
			<th lay-data="{field:'original_price', width:90,align:'center'}">价格(元)</th>
			<th lay-data="{field:'driver_phone', width:120,align:'center'}">司机手机号</th>
			<th lay-data="{field:'driver_name', width:90,align:'center'}">司机姓名</th>
			<th lay-data="{field:'franchisee_name', width:90,align:'center'}">所属运力</th>
			<th lay-data="{field:'orderStatus', width:120,align:'center'}">订单状态</th>
			<th lay-data="{fixed:'right', toolbar: '#operate', width:240, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>


	<script type="text/html" id="operate">
		<a class="layui-btn layui-btn-xs" lay-event="look">查看</a>

		{{# if( d.order_status < 2){ }}
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cancel">取消</a>
		{{# } }}


	</script>

	<script>
		layui.use(['table','laydate' ],function () {
			var table = layui.table, laydate = layui.laydate;
			//下单时间检索
			lay('.date').each(function(){
				laydate.render({
					elem: this
					,type: 'date'
					,trigger: 'click'
				});
			});
			var $ = layui.jquery, active = {
				search: function () {
					var book 			= $('#book').val(),										//类型 1预约订单 2实时订单
						start_time 		= $('#start').val(),									//时间 - 开始
						end_time 		= $('#end').val(),										//时间 - 结束
						order_sn 		= $('#order_sn').val(),									//订单号
						order_status 	= $('#order_status').val(),								//订单状态
						passenger_phone = $('#passenger_phone').val(),							//手机号 - 乘客
						driver_phone 	= $('#driver_phone').val(),								//手机号 - 司机
						real_phone 		= $('#real_phone').val(),								//手机号 - 司机
						province_id 	= $('#province_id').val(),								//省份
						city_id 		= $('#city_id').val(),									//城市
						pay_type 		= $('#pay_type').val(),									//支付方式 1支付2微信3余额
						all_order		= $('#all_order').val(),								//1普通订单2测试订单
						abnormal_order  = $('#abnormal_order').val(),
						start_pay_time	= $('#start_pay_time').val(),
						end_pay_time	= $('#end_pay_time').val(),
						freeze_status	= $('#freeze_status').val(),						//是否冻结
						franchisee_info = $('#franchisee_id').val();
							table.reload('test', {
						url: '/admin/Order/index', where: {
							"start_time" : start_time,
							"end_time" : end_time,
							"order_status" : order_status,
							"book" : book,
							"passenger_phone" : passenger_phone,
							"driver_phone" : driver_phone,
							"real_phone" : real_phone,
							"order_sn":order_sn,
							"province_id":province_id,
							"city_id":city_id,
							"pay_type":pay_type,
							"all_order":all_order,
							"abnormal_order":abnormal_order,
							"start_pay_time":start_pay_time,
							"end_pay_time":end_pay_time,
							"franchisee_info":franchisee_info,
							"freeze_status":freeze_status,
						}
					});
				}
				, excel: function () {
					var book 			= $('#book').val(),										//类型 1预约订单 2实时订单
						start_time 		= $('#start').val(),									//时间 - 开始
						end_time 		= $('#end').val(),										//时间 - 结束
						order_sn 		= $('#order_sn').val(),									//订单号
						order_status 	= $('#order_status').val(),								//订单状态
						passenger_phone = $('#passenger_phone').val(),							//手机号 - 乘客
						driver_phone 	= $('#driver_phone').val(),								//手机号 - 司机
						real_phone 		= $('#real_phone').val(),								//手机号 - 司机
						province_id 	= $('#province_id').val(),								//省份
						city_id 		= $('#city_id').val(),									//城市
						pay_type 		= $('#pay_type').val(),									//支付方式 1支付2微信3余额
						all_order 		= $('#all_order').val(),								//1普通订单2测试订单
						abnormal_order 	= $('#abnormal_order').val(),
						start_pay_time	= $('#start_pay_time').val(),
						end_pay_time	= $('#end_pay_time').val(),
						freeze_status	= $('#freeze_status').val();
					var str = "&pay_type="+pay_type+"&real_phone="+real_phone+"&start_pay_time="+start_pay_time+"&end_pay_time="+end_pay_time+"&all_order="+all_order+"&abnormal_order="+abnormal_order+"&start_time="+start_time+"&end_time="+end_time+"&order_status="+order_status+"&passenger_phone="+passenger_phone+"&driver_phone="+driver_phone+"&order_sn="+order_sn+"&book="+book+"&province_id="+province_id+"&city_id="+city_id+"&freeze_status"+freeze_status;
					layer.confirm('确认导出数据信息:', {
						btn: ['确认导出', '取消'] //可以无限个按钮
						, btn3: function (index, layero) {
							layer.close(index);
						}
					}, function (index, layero) {
						//按钮【按钮一】的回调
						location = "{:url('excel','headers=')}" + str ;
						layer.close(index);
					});
				}
			};
			$('.layui-btn').on('click', function () {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});

			//监听工具条
			table.on('tool(test)', function (obj) {
				var data = obj.data;
				var common_id = data.common_id;
				var driver_id = data.driver_id;
				var order_sn = data.order_sn;
				if (obj.event === 'cancel') {
					layer.prompt({
						formType: 2,
						title: '请输入取消原因'
					}, function (value, index, elem) {
						var common_id = data.common_id;
						var cancel_content = value;
						var url = "{:U('cancel_order')}";
						$.post(url, {'common_id': common_id,'cancel_content': cancel_content}, function (res) {
							switch (res['status']){
								case 1:
									layer.alert(res['msg'], {icon: 6},function () {
										var index = parent.layer.getFrameIndex(window.name);
										parent.layer.close(index);
										window.parent.location.reload()
									});
									break;
								default:
									layer.alert(res['msg'],{icon: 5});
									break;
							}
						}, 'json')
					});
				}else if (obj.event === 'look') {
					layer.open({
						type: 2,
						title: '订单信息详情',
						shadeClose: true,
						shade: 0.8,
						area: ['90%', '90%'],
						content: '{:url("/admin/order/excel","common_id=")}' + common_id //iframe的url
					});
				}else if (obj.event === 'travel') {
                    layer.open({
                        type: 2,
                        title: [data.driver_name+'运行轨迹','color:red;'],
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/order/travel","common_id=")}' + common_id //iframe的url
                    });
                }else if (obj.event === 'relieve') {
					layer.confirm('确认解除异常订单操作', function (index) {
						$.ajax({
							url:'{:url("/admin/order/relieve")}',
							async:true,
							dataType:'json',
							type:'POST',
							data:{'common_id':common_id,'driver_id':driver_id,'order_sn':order_sn},
							success:function(res){
								if(res.code==1){
									layer.msg(res.msg,{icon: 6});
								}else{
									layer.msg(res.msg,{icon: 5});
								}
								layer.close(loading);
							}
						});
					});
				}
                else if (obj.event === 'sound') { //查看录音
                    layer.open({
                        type: 2,
                        title: '订单'+data.order_sn+'的录音记录',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['800px', '500px'],
                        content: '{:url("/admin/inter_order/sound","common_id=")}' + common_id + "&order_type=1", //iframe的url  order_type 1快车  3城际 4顺风车
                    });
                }

			});

		});
		//选择省市切换
		function getProvinceList(){
			$("#city_id").empty();
			$("#city_id").append('<option value=>请选择城市</option>');
			var province_id = $("#province_id").val();
			$.ajax({
				url:'{:url("/admin/Franchisee/cityList")}',
				async:true,
				//dataType:'json',
				type:'post',
				data:{'province_id':province_id},
				success:function(res){
					$("#city_id").append(res);
				},
				error:function(e){
					layer.msg('请求错误');return false;
				}
			})
		};
	</script>
</block>
